<?php

namespace Modules\Manager\Http\Controllers;

use App\Helpers\ResponseData;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Manager\Entities\Department;

class DepartmentController extends Controller
{
    use ResponseData;
    public function list(Department $department,Request $request){
        $size = $request->input('size',10);
        $data = $department::query()
                ->with('user')
                ->orderBy('id','desc')->paginate($size);
        return $this->success($data);
    }
    public function store(Department $department,Request $request){
        $data = $request->all();
        $department->fill($data);
        $department->save();
        return $this->success('保存成功');
    }
    public function edit(Department $department,Request $request){
        $data = $department->find($request->id);
        return $this->success($data);
    }
    public function update(Department $department,Request $request){
        $data = $department->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(Department $department,Request $request){
        $data = $department->find($request->id);
        $data->delete();
    }
}
